import { lstatSync, readdirSync, realpathSync } from "fs";
import { resolve } from "path";

export const appDirectory = realpathSync(process.cwd());
export const resolveApp = (relativePath: string) =>
  resolve(appDirectory, relativePath);
export const SRC_FILE = resolveApp("src");

export const getAliases = (path = SRC_FILE) => {
  const alias: { [key: string]: string } = {};
  const files = readdirSync(path);
  files.forEach((item) => {
    const paths = resolve(path, item);
    const stat = lstatSync(paths);
    if (stat.isDirectory() === true) {
      alias[`@${item}`] = paths;
    }
  });
  return {
    "@": path,
    ...alias,
  };
};